-- 悬停区域组件，当鼠标进入时，会将自身状态设置为悬停
HoverArea = {
}


local function checkHoverOut(self, x, y)
    if not self:hitTest(x, y) then
        self.hovered = false
        if self.subStyle == "hover" then
            self.subStyle = "none"
        end
        EventDispatcher.global:off(NodeEvent.MouseMoved, checkHoverOut, self)
        self:emit(NodeEvent.HoverOut)
    end
end

local function onMouseMovedIn(self)
    if self.hovered then
        return
    end
    self.hovered = true
    if self.subStyle == "none" then
        self.subStyle = "hover"
    end
    self:emit(NodeEvent.HoverIn)
    EventDispatcher.global:on(NodeEvent.MouseMoved, checkHoverOut, self)
end

function HoverArea:ctor()
    self.hovered = false
    self:on(NodeEvent.MouseMoved, onMouseMovedIn, self)
    self.interactable = true
end
